package demo.springboot.Controller;

import demo.springboot.POJO.T_news;
import demo.springboot.service.T_newsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping(value = "/")
public class Index {

    private static final String REDIRECT_TO_BOOK_URL = "redirect:/book";

    @Autowired
    T_newsService newsService;



    @GetMapping(value = "")
    public String getBookList(ModelMap map, Model model) {
        List<T_news> news = newsService.findAll();

        Date date = null;
        news = news.subList(0, 8);
        for (int i = 0; i < news.size(); i++) {
            String times = news.get(i).getTime_stamp();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String dateeeee = sdf.format(new Date(Long.parseLong(String.valueOf(  Long.parseLong( times )* 1000))));

//            Long l=(str);//返回基本数据类型long

            news.get(i).setTime_stamp(dateeeee);
        }
        model.addAttribute("news", news.subList(0, 8));
        return "index.html";
    }




    // 企业文化
    @GetMapping(value = "/companyculture")
    public String CompanyCulture(ModelMap map, Model model) {
        return "about/CompanyCulture.html";
    }


}
